home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1599 / 1264 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  3.7 KB

  1. From: bousch@topo.matups.fr (Thierry Bousch)
  2. Subject: Re: external device drivers
  3. Date: Sun, 10 Apr 1994 21:20:26 +0200 (MET DST)
  4. In-Reply-To: <9404100126.AA00732@tazboy.JPL.NASA.GOV> from "Brad Pickering" at Apr 9, 94 06:26:41 pm
  5.  
  6. Hello Brad,
  7.  
  8. > I am trying to write an external device driver for the
  9. > Mac port of MiNT, but I am unclear on the use of wake
  10. > and sleep (among other things).  I would like to have
  11. > a device that other Mac applications can send data
  12. > to and have the device pass that data on to a mint
  13. > program when it is read.  My first question is: does
  14. > this device have to be a TTY device?  I thought the
  15. > answer was yes, because the kernel had built in support
  16. > for putting a process to sleep if it tried to read a TTY
  17. > device with no data available, but now I'm not sure.  When
  18.  
  19. If you only intend to use the driver in RAW mode (a printer for
  20. instance), it's not necessary to declare it as a TTY device. On the
  21. other hand, if you need terminal handling services (line discipline,
  22. XON/XOFF, signals), you'll have to define it as a TTY device; a typical
  23. example is a serial line driver. The services above (CBREAK mode) are
  24. provided by the kernel, so in theory you don't have to care about them.
  25. (In fact, you have to; see below.)
  26.  
  27. > I thought the kernel would automatically put a process to
  28. > sleep I though that the only sleep/wake call I would need
  29. > was a call to wakeselect in the routine that is called when
  30. > data arrives from another Mac application.  Now I am thinking
  31. > that I might need to call sleep in the read routine, but I don't
  32. > know which queue or condition to sleep on.  I also don't know
  33. > if I need to change the wake call in the data ready routine
  34. > depending on whether I am sleeping because of a select call
  35. > or a read call.
  36.  
  37. The simplest (and for now, unique) way to handle this situation is to
  38. wait for incoming characters in a small loop in your read() routine. If
  39. you don't want this loop to eat too much CPU time, insert a
  40. nap() or yield() instruction inside.
  41.  
  42. Of course, it would be much more elegant to bring the process to
  43. sleep(). But who will wake it again? You obviously need another thread
  44. of execution to wait for incoming characters (and for other tasks of
  45. supervision) and wake it up; ideally, this thread should execute in
  46. kernel mode so that one can invoke wake() (which is a kernel call). 
  47. If Kai Roemer's proposition of adding addroottimeout() to MiNT 1.11 is
  48. adopted, this would be possible; for now, it isn't.
  49.  
  50. > If anybody has any ideas on this, or some source code, or some
  51. > pointers to documentation, I would like to hear about it.  I
  52. > have read parts of the modem driver and the raw disk driver
  53. > on atari.archive but this stuff still doesn't quite make sense
  54. > to me.
  55.  
  56. Examine the 'clockdev' device included in early MiNT distributions. The
  57. raw disk device driver is simple, too: in both cases, the read() and
  58. write() operations will never block.
  59.  
  60. The modem driver is certainly not the simplest one, unfortunately. 
  61. There is a big problem with the way MiNT considers device drivers; they
  62. are invoked only when the user wants to issue a read/write operation.
  63. Suppose you are remotely logged, and you spawn a program like this one:
  64.  
  65.   main()  { while(1); }
  66.  
  67. You'll never be able to kill this process, no matter how hard you press
  68. ^C or ^\. Since the program does no I/O, the device driver functions
  69. (read/write) will never be called. If they were called, the kernel would
  70. notice the incoming ^C character and kill the process; unfortunately,
  71. they aren't.
  72.  
  73. This "synchronous" interface to the driver complicates things
  74. tremendously, because you have to create a new thread of execution
  75. where, among other things, you handle ^C/^S/^Q just like the kernel
  76. would (if it could see them!!)
  77.  
  78. Thierry.
  79.  
  80.